package io;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

/**
 * 文件复制
 */
public class CopyDemo {
    public static void main(String[] args) throws IOException {
        FileInputStream fis = new FileInputStream("image.jpeg");
        FileOutputStream fos = new FileOutputStream("image_cp.jpeg");

        /*
            image.jpg文件内容
            11010001 11001100 00101110 ...
            ^^^^^^^^
            d = fis.read();

            d:00000000 00000000 00000000 11010001

            fos.write(d);写d二进制的后8位

            image_cp.jpg文件内容
            11010001
         */
        int d;
        long start = System.currentTimeMillis();
        while((d = fis.read()) != -1) {
            fos.write(d);
        }
        long end = System.currentTimeMillis();
        System.out.println("复制完毕!耗时："+(end-start)+"ms");
        fis.close();
        fos.close();
    }
}
